/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Random;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

/**
 *
 * @author Kenn
 */
@Entity
public class RawMaterialSupplyInformation implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToOne(targetEntity = RawMaterial.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private RawMaterial rawMaterial;
    @ManyToOne(targetEntity = Supplier.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private Supplier supplier;
    private Boolean currency;
    private Double unitPriceSGD;
    private Double unitPriceUSD;
    private Double unitLotPriceSGD;
    private Double unitLotPriceUSD;
    private Timestamp hiddenId;

    public RawMaterialSupplyInformation() {
        this.rawMaterial = null;
        this.supplier = null;
        this.unitPriceSGD = 0D;
        this.unitPriceUSD = 0D;
        this.unitLotPriceSGD = 0D;
        this.unitLotPriceUSD = 0D;
        
        Random rand = new Random();
        long seed = new Date().getTime() + (long)rand.nextInt(10000);
        hiddenId = new Timestamp(seed);
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public RawMaterial getRawMaterial() {
        return rawMaterial;
    }

    public void setRawMaterial(RawMaterial rawMaterial) {
        this.rawMaterial = rawMaterial;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public Boolean getCurrency() {
        return currency;
    }

    public Timestamp getHiddenId() {
        return hiddenId;
    }

    public void setHiddenId(Timestamp hiddenId) {
        this.hiddenId = hiddenId;
    }

    public void setCurrency(Boolean currency) {
        this.currency = currency;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public Double getUnitPriceSGD() {
        return unitPriceSGD;
    }

    public void setUnitPriceSGD(Double unitPriceSGD) {
        this.unitPriceSGD = unitPriceSGD;
    }

    public Double getUnitPriceUSD() {
        return unitPriceUSD;
    }

    public void setUnitPriceUSD(Double unitPriceUSD) {
        this.unitPriceUSD = unitPriceUSD;
    }
    
    @Override
    public RawMaterialSupplyInformation clone(){
        RawMaterialSupplyInformation r = new RawMaterialSupplyInformation();
        r.setRawMaterial(rawMaterial);
        r.setSupplier(supplier);
        r.setUnitPriceSGD(unitPriceSGD);
        r.setUnitPriceUSD(unitPriceUSD);
        r.setUnitLotPriceSGD(unitLotPriceSGD);
        r.setUnitLotPriceUSD(unitLotPriceUSD);
        r.setCurrency(currency);
        r.setHiddenId(hiddenId);
        return r;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RawMaterialSupplyInformation)) {
            return false;
        }
        RawMaterialSupplyInformation other = (RawMaterialSupplyInformation) object;
        // Compare hiddenId
        if(!this.hiddenId.equals(other.hiddenId))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.RawMaterialSupplyInformation[ id=" + id + " ]";
    }

    /**
     * @return the unitLotPriceSGD
     */
    public Double getUnitLotPriceSGD() {
        return unitLotPriceSGD;
    }

    /**
     * @param unitLotPriceSGD the unitLotPriceSGD to set
     */
    public void setUnitLotPriceSGD(Double unitLotPriceSGD) {
        this.unitLotPriceSGD = unitLotPriceSGD;
    }

    /**
     * @return the unitLotPriceUSD
     */
    public Double getUnitLotPriceUSD() {
        return unitLotPriceUSD;
    }

    /**
     * @param unitLotPriceUSD the unitLotPriceUSD to set
     */
    public void setUnitLotPriceUSD(Double unitLotPriceUSD) {
        this.unitLotPriceUSD = unitLotPriceUSD;
    }
}
